home *** CD-ROM | disk | FTP | other *** search
Wrap
Java Source | 2001-06-23 | 14.4 KB | 472 lines
/* ArcanaApp.SpellEditFrame - an interface by which to edit the spell records of the spellbook. Written by Scott C. Ziegler for use with Simulcra™. vers. history: 07.08.00 - achieved syntactically correct version. 09.19.00 - decided to overhaul project using layout managers 10.25.00 - began project to make a functional spell book app 12.12.00 - finalized first version of API for GUI (menus remain), added area of effect field and label Work Needed: - finish initMenus() - complete the ComboBox implementation details !!!IMPORTANT!!! - link events with underlying code libs (i.e. SpellRecord, SpellFiling, etc.) - add JDialog error handlers. - add JDialog warnings to delete and clear record buttons. Work Completed: - added menu items and categories - added event architecture to buttons etc. - made AreaOfEffect textfield and label */ /* This file and its intellectual contents are considered property of the creator and are to be treated as such with respect to use in other applications. Any use of this software for any purpose whatsoever must have explicit permission from the author of the file. This code is part of an ongoing development process for future possible products, and so is considered private property. Do not use without permission. Author: Scott C. Ziegler <Aslan@Narnia.net> */ package Thoth; import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; public class SpellEditFrame extends JFrame { Insets objectInsets = new Insets(2,2,2,2); // Panels JPanel buttonPanel; JPanel recordPanel; // Menus JMenuBar menuBar; JMenu fileMenu; JMenuItem aboutBoxMenuItem; JMenuItem quitMenuItem; JMenu editMenu; JMenuItem undoMenuItem; JMenuItem cutMenuItem; JMenuItem copyMenuItem; JMenuItem pasteMenuItem; JMenu optionsMenu; JMenuItem optionsMenuItem; JMenu someMenu; JMenuItem someMenuItem; // Buttons JButton backButton; JButton nextButton; JButton prevLvlButton; JButton fwdLvlButton; JButton viewButton; JButton saveButton; JButton clearButton; JButton newButton; // Labels JLabel nameLabel; JLabel levelLabel; JLabel schoolLabel; JLabel componentsLabel; JLabel rangeLabel; JLabel durationLabel; JLabel castingTimeLabel; JLabel areaOfEffectLabel; JLabel savingThrowLabel; JLabel descriptionLabel; // Text Fields JTextField nameTextField; JTextField levelTextField; JComboBox schoolComboBox; JComboBox componentsComboBox; JTextField rangeTextField; JTextField durationTextField; JTextField castingTimeTextField; JTextField areaOfEffectTextField; JTextField savingThrowTextField; JScrollPane descriptionScrollPane; JTextArea descriptionTextArea; ActionListener navigationListener; ActionListener manipulationListener; ActionListener aboutListener; ActionListener quitListener; // Constructors public SpellEditFrame() { super("Arcana Spell Edit"); initMenus(); initButtons(); initRecordPanel(); initDescriptionArea(); setJMenuBar(menuBar); Container progFrameContentPane = getContentPane(); progFrameContentPane.add(buttonPanel, BorderLayout.NORTH); progFrameContentPane.add(recordPanel, BorderLayout.CENTER); progFrameContentPane.add(descriptionScrollPane, BorderLayout.SOUTH); setSize(new Dimension(500,600)); //setVisible(true); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { thisWindowClosing(e); } }); } // Selectors public Arcana.SpellRecord getSpell() { Arcana.SpellRecord spell = new Arcana.SpellRecord(); spell.setLevel(Integer.parseInt(levelTextField.getText())); spell.setName(nameTextField.getText()); spell.setSchool((String)schoolComboBox.getSelectedItem()); spell.setRange(rangeTextField.getText()); spell.setComponentsByString((String)componentsComboBox.getSelectedItem()); spell.setDuration(durationTextField.getText()); spell.setCastingTime(castingTimeTextField.getText()); spell.setAreaOfEffect(areaOfEffectTextField.getText()); spell.setSavingThrow(savingThrowTextField.getText()); spell.setEffect(new Arcana.SpellDescription(new String(descriptionTextArea.getText()))); return spell; } // Mutators public void setNavigationListener(ActionListener nl) { backButton.removeActionListener(navigationListener); backButton.addActionListener(nl); nextButton.removeActionListener(navigationListener); nextButton.addActionListener(nl); fwdLvlButton.removeActionListener(navigationListener); fwdLvlButton.addActionListener(nl); prevLvlButton.removeActionListener(navigationListener); prevLvlButton.addActionListener(nl); } public void setManipulationListener(ActionListener ml) { viewButton.removeActionListener(manipulationListener); viewButton.addActionListener(ml); saveButton.removeActionListener(manipulationListener); saveButton.addActionListener(ml); clearButton.removeActionListener(manipulationListener); clearButton.addActionListener(ml); newButton.removeActionListener(manipulationListener); newButton.addActionListener(ml); } public void setAboutListener(ActionListener al) { aboutBoxMenuItem.removeActionListener(aboutListener); aboutBoxMenuItem.addActionListener(al); } public void setQuitListener(ActionListener ql) { quitMenuItem.removeActionListener(quitListener); quitMenuItem.addActionListener(ql); } // Methods private void initMenus() { menuBar = new JMenuBar(); menuBar.setBorder(new BevelBorder(BevelBorder.RAISED)); fileMenu = new JMenu("File"); fileMenu.setMnemonic('F'); aboutBoxMenuItem = new JMenuItem("About…"); fileMenu.add(aboutBoxMenuItem); aboutListener = new ActionListener() { public void actionPerformed(ActionEvent ae) { } }; aboutBoxMenuItem.addActionListener(aboutListener); quitMenuItem = new JMenuItem("Quit"); fileMenu.add(quitMenuItem); quitListener = new ActionListener() { public void actionPerformed(ActionEvent ae) { System.exit(0); } }; quitMenuItem.addActionListener(quitListener); editMenu = new JMenu("Edit"); undoMenuItem = new JMenuItem("Undo"); editMenu.add(undoMenuItem); cutMenuItem = new JMenuItem("Cut"); editMenu.add(cutMenuItem); copyMenuItem = new JMenuItem("Copy"); editMenu.add(copyMenuItem); pasteMenuItem = new JMenuItem("Paste"); editMenu.add(pasteMenuItem); optionsMenu = new JMenu("Options"); optionsMenuItem = new JMenuItem("Options…"); optionsMenu.add(optionsMenuItem); someMenu = new JMenu("Something"); someMenuItem = new JMenuItem("Something…"); menuBar.add(fileMenu); menuBar.add(editMenu); menuBar.add(optionsMenu); menuBar.add(someMenu); } private void initButtons() { navigationListener = new ActionListener() { public void actionPerformed(ActionEvent ae) { String com = ae.getActionCommand(); if (com.compareTo("Back") == 0) { } else if (com.compareTo("Next") == 0) { } else if (com.compareTo("PrevLvl") == 0) { } else if (com.compareTo("FwdLvl") == 0) { } } }; manipulationListener = new ActionListener() { public void actionPerformed(ActionEvent ae) { String com = ae.getActionCommand(); if (com.compareTo("View") == 0) { } else if (com.compareTo("Save") == 0) { } else if (com.compareTo("Clear") == 0) { } else if (com.compareTo("New") == 0) { } } }; backButton = new JButton("Back"); backButton.addActionListener(navigationListener); nextButton = new JButton("Next"); nextButton.addActionListener(navigationListener); prevLvlButton = new JButton("PrevLvl"); prevLvlButton.addActionListener(navigationListener); fwdLvlButton = new JButton("FwdLvl"); fwdLvlButton.addActionListener(navigationListener); viewButton = new JButton("View"); viewButton.addActionListener(manipulationListener); saveButton = new JButton("Save"); saveButton.addActionListener(manipulationListener); clearButton = new JButton("Clear"); clearButton.addActionListener(manipulationListener); newButton = new JButton("New"); newButton.addActionListener(manipulationListener); buttonPanel = new JPanel(); buttonPanel.setLayout(new GridLayout(2,4,5,5)); buttonPanel.add(backButton); buttonPanel.add(nextButton); buttonPanel.add(viewButton); buttonPanel.add(clearButton); buttonPanel.add(prevLvlButton); buttonPanel.add(fwdLvlButton); buttonPanel.add(saveButton); buttonPanel.add(newButton); } private void initRecordPanel() { recordPanel = new JPanel(); recordPanel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); nameLabel = new JLabel("Name:"); nameTextField = new JTextField(); levelLabel = new JLabel("Level:"); levelTextField = new JTextField(); schoolLabel = new JLabel("School:"); schoolComboBox = new JComboBox(); componentsLabel = new JLabel("Components:"); componentsComboBox = new JComboBox(); rangeLabel = new JLabel("Range:"); rangeTextField = new JTextField(); durationLabel = new JLabel("Duration"); durationTextField = new JTextField(); castingTimeLabel = new JLabel("Casting Time:"); castingTimeTextField = new JTextField(); areaOfEffectLabel = new JLabel("Area Of Effect"); areaOfEffectTextField = new JTextField(); savingThrowLabel = new JLabel("Saving Throw:"); savingThrowTextField = new JTextField(); descriptionLabel = new JLabel("Description:"); schoolComboBox.addItem("Abjuration"); schoolComboBox.addItem("Alteration"); schoolComboBox.addItem("Conjuration/Summoning"); schoolComboBox.addItem("Enchantment/Charm"); schoolComboBox.addItem("Illusion/Phantasm"); schoolComboBox.addItem("Invocation/Evocation"); schoolComboBox.addItem("Divination"); schoolComboBox.addItem("Necromancy"); schoolComboBox.addItem("Wild Magic"); componentsComboBox.addItem("Verbal"); componentsComboBox.addItem("Somantic"); componentsComboBox.addItem("Material"); componentsComboBox.addItem("Verbal, Somantic"); componentsComboBox.addItem("Somantic, Material"); componentsComboBox.addItem("Verbal, Material"); componentsComboBox.addItem("Verbal, Somantic, Material"); setGBConstraints(c,0,0,true); recordPanel.add(nameLabel, c); setGBConstraints(c,1,0,false); recordPanel.add(nameTextField, c); setGBConstraints(c,0,1,true); recordPanel.add(levelLabel, c); setGBConstraints(c,1,1,false); recordPanel.add(levelTextField, c); setGBConstraints(c,0,2,true); recordPanel.add(schoolLabel, c); setGBConstraints(c,1,2,false); recordPanel.add(schoolComboBox, c); setGBConstraints(c,0,3,true); recordPanel.add(componentsLabel, c); setGBConstraints(c,1,3,false); recordPanel.add(componentsComboBox, c); setGBConstraints(c,0,4,true); recordPanel.add(rangeLabel, c); setGBConstraints(c,1,4,false); recordPanel.add(rangeTextField, c); setGBConstraints(c,0,5,true); recordPanel.add(durationLabel, c); setGBConstraints(c,1,5,false); recordPanel.add(durationTextField, c); setGBConstraints(c,0,6,true); recordPanel.add(castingTimeLabel, c); setGBConstraints(c,1,6,false); recordPanel.add(castingTimeTextField, c); setGBConstraints(c,0,7,true); recordPanel.add(areaOfEffectLabel, c); setGBConstraints(c,1,7,false); recordPanel.add(areaOfEffectTextField, c); setGBConstraints(c,0,8,true); recordPanel.add(savingThrowLabel, c); setGBConstraints(c,1,8,false); recordPanel.add(savingThrowTextField, c); setGBConstraints(c,0,9,true); recordPanel.add(descriptionLabel, c); } private void setGBConstraints(GridBagConstraints gbc, int x, int y, boolean lbl_field) { gbc.gridx = x; gbc.gridy = y; gbc.gridheight = 1; gbc.gridwidth = 1; gbc.weightx = (lbl_field?20:80); gbc.weighty = 11; gbc.fill = (lbl_field?GridBagConstraints.NONE:GridBagConstraints.BOTH); gbc.anchor = (lbl_field?GridBagConstraints.WEST:GridBagConstraints.CENTER); gbc.insets = objectInsets; } private void initDescriptionArea() { descriptionScrollPane = new JScrollPane(); descriptionTextArea = new JTextArea(); descriptionTextArea.setRows(15); descriptionTextArea.setLineWrap(true); descriptionTextArea.setWrapStyleWord(true); descriptionScrollPane.getViewport().add(descriptionTextArea); // sizing? } // Close the window when the close box is clicked void thisWindowClosing(java.awt.event.WindowEvent e) { setVisible(false); clearFields(); // dispose(); // System.exit(0); } public void clearFields() { nameTextField.setText(""); levelTextField.setText(""); rangeTextField.setText(""); durationTextField.setText(""); castingTimeTextField.setText(""); areaOfEffectTextField.setText(""); savingThrowTextField.setText(""); descriptionTextArea.setText(""); schoolComboBox.setSelectedIndex(0); componentsComboBox.setSelectedIndex(0); } // need to make selection criteria less rigid. "contains?" predicates perhaps? public void displaySpell(Arcana.SpellRecord spell) { nameTextField.setText(spell.getName()); levelTextField.setText("" + spell.getLevel()); if (spell.getSchool().compareTo("Abjuration") == 0) { schoolComboBox.setSelectedIndex(0); } else if (spell.getSchool().compareTo("Alteration") == 0) { schoolComboBox.setSelectedIndex(1); } else if (spell.getSchool().compareTo("Conjuration/Summoning") == 0) { schoolComboBox.setSelectedIndex(2); } else if (spell.getSchool().compareTo("Enchantment/Charm") == 0) { schoolComboBox.setSelectedIndex(3); } else if (spell.getSchool().compareTo("Illusion/Phantasm") == 0) { schoolComboBox.setSelectedIndex(4); } else if (spell.getSchool().compareTo("Invocation") == 0 || spell.getSchool().compareTo("Evocation") == 0) { schoolComboBox.setSelectedIndex(5); } else if (spell.getSchool().compareTo("Divination") == 0) { schoolComboBox.setSelectedIndex(6); } else if (spell.getSchool().compareTo("Necromancy") == 0) { schoolComboBox.setSelectedIndex(7); } else if (spell.getSchool().compareTo("Wild Magic") == 0) { schoolComboBox.setSelectedIndex(8); } componentsComboBox.setSelectedIndex(spell.getComponents() - 1); rangeTextField.setText(spell.getRange()); durationTextField.setText(spell.getDuration()); castingTimeTextField.setText(spell.getCastingTime()); areaOfEffectTextField.setText(spell.getAreaOfEffect()); savingThrowTextField.setText(spell.getSavingThrow()); descriptionTextArea.setText(spell.getEffect().getDescription()); } }